#include <iostream>
#include <iomanip>
#include <cmath>

int main() {
    std::cout << std::fixed << std::setprecision(17);
    
    // 0.075的二进制表示分析
    double target = 0.075;
    
    // 找到0.075周围最接近的可表示浮点数
    double smaller = std::nextafter(target, 0.0);    // 向下一个
    double larger = std::nextafter(target, 1.0);     // 向上一个
    
    std::cout << "=== 0.075 周围的可表示浮点数 ===" << std::endl;
    std::cout << "较小值: " << smaller << std::endl;
    std::cout << "理论值: " << target << std::endl;
    std::cout << "较大值: " << larger << std::endl;
    
    // 计算到0.075的精确距离
    double dist_smaller = 0.075 - smaller;
    double dist_larger = larger - 0.075;
    
    std::cout << "\n距离 0.075 的精确差值:" << std::endl;
    std::cout << "较小值到0.075的距离: " << dist_smaller << std::endl;
    std::cout << "较大值到0.075的距离: " << dist_larger << std::endl;
    
    // 哪个更接近？
    if (dist_smaller < dist_larger) {
        std::cout << "\n✅ 较小值更接近0.075" << std::endl;
        std::cout << "所以 FE_TONEAREST 会选择: " << smaller << std::endl;
    } else if (dist_larger < dist_smaller) {
        std::cout << "\n✅ 较大值更接近0.075" << std::endl;
        std::cout << "所以 FE_TONEAREST 会选择: " << larger << std::endl;
    } else {
        std::cout << "\n✅ 距离相等，使用银行家舍入" << std::endl;
    }
    
    return 0;
}

